import argparse, pandas as pd, numpy as np
from astropy.coordinates import SkyCoord
import astropy.units as u

def load_catalog(path):
    df = pd.read_csv(path)
    assert {'RA','DEC','mag'}.issubset(df.columns), "CSV 需包含 RA, DEC, mag"
    sc = SkyCoord(ra=df['RA'].values*u.deg, dec=df['DEC'].values*u.deg, frame='icrs')
    df['x'] = np.cos(sc.ra.rad)*np.cos(sc.dec.rad)
    df['y'] = np.sin(sc.ra.rad)*np.cos(sc.dec.rad)
    df['z'] = np.sin(sc.dec.rad)
    return df

if __name__ == "__main__":
    ap = argparse.ArgumentParser()
    ap.add_argument("--check", type=str, required=True)
    args = ap.parse_args()
    df = load_catalog(args.check)
    print(df.head())
    print(f"Loaded {len(df)} stars.")